package com.example.mapper;

import com.example.domain.dto.TimeDTO;
import com.example.domain.po.Chapter;
import com.example.domain.po.Course;
import com.example.domain.po.FilePO;
import com.example.domain.vo.CourseContentVo;
import com.example.domain.vo.CourseSum;
import com.example.domain.vo.CourseVo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

public interface CourseMapper {

    List<CourseVo> list(@Param("name") String name, @Param("department") String department);

    Integer add(Course course);

    List<Map<String,Object>> listByHeat();

    List<Map<String, Object>> listByVip(Integer type);

    void del(Integer id);

    void update(Course course);

    @Select("select * from course where id=#{courseId}")
    Course findById(Integer courseId);

    List<Map<String, Object>> listByLike(String name);


    List<CourseVo> recommend(@Param("type") Integer type,@Param("userId") Integer userId);

    Map<String,Object> getById(Integer id);

    @Select(" select  count(*) num  ,sum(price) total  from orders o  , course c  WHERE  o.course_id = c.id  and c.docker_id =#{userId}  and c.type =#{type}")
    CourseSum sum(@Param("userId") Integer userId,@Param("type") Integer type);

    @Select(" select  count(*) num  ,sum(price) total  from orders o  , course c  WHERE  o.course_id = c.id  and o.user_id =#{userId}  and c.type =#{type}")
    CourseSum sumBuy(@Param("userId") Integer userId,@Param("type") Integer type);


    List<CourseContentVo>  getCourseContent(@Param("courseId") Integer courseId, @Param("courseName") String courseName,@Param("doctorName") String doctorName);

    @Select("select f_id  fileId, f_md5 md5, f_name name  ,detail ,f_size size ,chapter_id from file where chapter_id=#{cid}")
    List<FilePO> finFileByChapterId(int cid);

    @Insert("insert into  chapter (name, course_id) VALUES (#{name},#{courseId})")
    void addChapter(Chapter chapter);
    void update2(Course course);

    List<Map<String, Object>> listCFByCid(Integer id);

    @Update("update chapter set name =#{name} where id = #{cid}")
    void updateChapter(Chapter chapter);

    @Insert("insert into file(f_name,chapter_id) values (#{name},#{cid})")
    void addTime(TimeDTO timeDTO);

    @Update("update file set f_name =#{name} where f_id=#{fileId}")
    void updateTime(TimeDTO timeDTO);
}
